var app = getApp()

Page({
  data: {
    server: app.api.server,
    imgUrls: null,
    surveys: [],
  },
  onLoad: function() {
        
    if (app.globalData.userInfo.is_superuser) {//超级管理员开启
      this.selectComponent("#footer").showButton(2);
    }

    var imgUrls = [{      id: 7,        src: this.data.server + '/images/swiper1.jpg'      },
      {        id: 8,        src: this.data.server + '/images/swiper2.jpg'      },
      {        id: 9,        src: this.data.server + '/images/swiper3.jpg'      },    ]
    this.setData({
      imgUrls: imgUrls
    });

    this.refreshmethod(true)
  },
  onPullDownRefresh: function() {
    this.refreshmethod(false)
  },
  paper: function() {
    wx.navigateTo({
      url: '../questionnaire/questionnaire'
    })
  },
  mine: function() {
    wx.navigateTo({
      url: '../mine/mine'
    })
  },
  refreshmethod: function(load) {
    wx.showNavigationBarLoading()
    var that = this
    wx.request({
      url: this.data.server + '/showAllSurvey.action',
      data: {userid:app.globalData.userInfo.userid,is_superuser:app.globalData.userInfo.is_superuser},
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res) {
        // success
        that.data.surveys = res.data.surveyList;
        that.setData({
          surveys: res.data.surveyList
        })
        wx.hideNavigationBarLoading()
        if (load == false)
          wx.stopPullDownRefresh()
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  }
})